package com.bos.prop.controller;

import com.bos.dao.KabupatenDAO;
import com.bos.dao.TahunDAO;
import com.bos.domain.Kabupaten;
import com.bos.editor.KabupatenEditor;
import com.bos.util.enums.Bulan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * User: Deny Prasetyo, S.T.
 * http://www.jasoet.com
 */
@Controller
public class HomeController {

    private TahunDAO tahunDAO;
    private KabupatenDAO kabupatenDAO;

    @Autowired
    public void setTahunDAO(TahunDAO tahunDAO) {
        this.tahunDAO = tahunDAO;
    }

    @Autowired
    public void setKabupatenDAO(KabupatenDAO kabupatenDAO) {
        this.kabupatenDAO = kabupatenDAO;
    }

    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String home(ModelMap modelMap) {
        Calendar calendar = new GregorianCalendar();
        modelMap.addAttribute("year", calendar.get(Calendar.YEAR));
        modelMap.addAttribute("date", calendar.get(Calendar.DATE));
        modelMap.addAttribute("month", Bulan.valueOf(calendar.get(Calendar.MONTH)) + "");
        modelMap.addAttribute("name", "Propinsi");
        modelMap.addAttribute("kabMenuList", kabupatenDAO.getAll());
        return "/home";
    }

    @RequestMapping(value = "/produkHukum", method = RequestMethod.GET)
    public String produkHukum(ModelMap modelMap) {
        Calendar calendar = new GregorianCalendar();
        modelMap.addAttribute("year", calendar.get(Calendar.YEAR));
        modelMap.addAttribute("date", calendar.get(Calendar.DATE));
        modelMap.addAttribute("month", Bulan.valueOf(calendar.get(Calendar.MONTH)) + "");
        modelMap.addAttribute("name", "Propinsi");
        modelMap.addAttribute("kabMenuList", kabupatenDAO.getAll());
        return "/produkHukum";
    }

    @RequestMapping(value = "/contactPerson", method = RequestMethod.GET)
    public String contactPerson(ModelMap modelMap) {
        Calendar calendar = new GregorianCalendar();
        modelMap.addAttribute("year", calendar.get(Calendar.YEAR));
        modelMap.addAttribute("date", calendar.get(Calendar.DATE));
        modelMap.addAttribute("month", Bulan.valueOf(calendar.get(Calendar.MONTH)) + "");
        modelMap.addAttribute("name", "Propinsi");
        modelMap.addAttribute("kabMenuList", kabupatenDAO.getAll());
        return "/contactPerson";
    }

    @RequestMapping(value = "/profil", method = RequestMethod.GET)
    public String profil(ModelMap modelMap) {
        Calendar calendar = new GregorianCalendar();
        modelMap.addAttribute("year", calendar.get(Calendar.YEAR));
        modelMap.addAttribute("date", calendar.get(Calendar.DATE));
        modelMap.addAttribute("month", Bulan.valueOf(calendar.get(Calendar.MONTH)) + "");
        modelMap.addAttribute("name", "Propinsi");
        modelMap.addAttribute("kabMenuList", kabupatenDAO.getAll());
        return "/profil";
    }

    @InitBinder
    protected void initBinder(WebDataBinder binder) throws Exception {
        binder.registerCustomEditor(Kabupaten.class, new KabupatenEditor(kabupatenDAO));
    }
}
